<template>
  <div>
    <el-dialog
      v-bind="$attrs"
      v-on="$listeners"
      @open="onOpen"
      @close="onClose"
      title="修改密码"
      width="500px"
      :visible.sync="dialogVisible"
    >
      <el-row :gutter="15">
        <el-form
          ref="passwordForm"
          :model="passwordData"
          :rules="passwordRules"
          size="medium"
          label-width="100px"
        >
          <el-col :span="20">
            <el-form-item label="旧密码" prop="oldPassword">
              <el-input
                v-model="passwordData.oldPassword"
                placeholder="请输入密码旧密码"
                clearable
                show-password
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="新密码" prop="newPassword">
              <el-input
                v-model="passwordData.newPassword"
                placeholder="请输入新密码"
                clearable
                show-password
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="确认密码" prop="checkPassword">
              <el-input
                v-model="passwordData.checkPassword"
                placeholder="请输入确认密码"
                clearable
                show-password
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div slot="footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="handelConfirm">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { sendJSON } from "@/utils/request";
export default {
  inheritAttrs: false,
  components: {},
  props: [],
  data() {
    return {
      passwordData: {
        oldPassword: undefined,
        newPassword: undefined,
        checkPassword: undefined
      },
      passwordRules: {
        oldPassword: [
          {
            required: true,
            message: "请输入密码旧密码",
            trigger: "blur"
          }
        ],
        newPassword: [
          {
            required: true,
            message: "请输入新密码",
            trigger: "blur"
          }
        ],
        checkPassword: [
          {
            required: true,
            message: "请输入确认密码",
            trigger: "blur"
          }
        ]
      },
      dialogVisible: false
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    onOpen() {},
    onClose() {
      this.$refs["passwordForm"].resetFields();
    },
    close() {
      this.dialogVisible = false;
    },
    handelConfirm() {
      this.$refs["passwordForm"].validate(valid => {
        if (!valid) return;
        if (this.passwordData.newPassword != this.passwordData.checkPassword) {
          this.$message("两次输入的密码不一致~");
          return;
        }
        sendJSON("sys/user/updMsf", this.passwordData).then(res => {
          this.$message.success(res.msg);
          this.dialogVisible = false;
          this.$emit("updData");
        });
      });
    }
  }
};
</script>
<style></style>
